package composite.abstrac;

import composite.view.View;
import log.Log;

import java.util.ArrayList;
import java.util.List;

public abstract class AbstractFloder extends Component implements View {

    private final List<Component> childComponents = new ArrayList<Component>();

    public AbstractFloder(String name) {
        super(name);
    }

    @Override
    public void onDraw() {
        drawSpan(deepth);
        Log.printName(this.name + "/", getColor());
        System.out.println();
        for (Component childComponent : childComponents) {
            childComponent.deepth = this.deepth + 1;
            ((View) childComponent).onDraw();
        }
    }

    @Override
    public String getColor() {
        if (this.childComponents.isEmpty()) {
            return Log.red;
        } else {
            return Log.green;
        }
    }

    @Override
    public String getBgColor(String buider) {
        if (buider.length() % 3 == 0) {
            return "43";
        } else if (buider.length() % 3 == 1) {
            return "44";
        } else return "46";
    }

    public void addChild(Component child) {
        child.parent=this;
        this.childComponents.add(child);
    }


    public void removeChild(int index) {
        this.childComponents.remove(index);
    }

    public List<Component> getChild() {
        return this.childComponents;
    }

}
